import { Config } from "../../config/Config";
import { Logger } from "./Logger";

const child_process = require('child_process');

export class ShellHelper {

    public static async getOnline(port: number = 7520):Promise<number> {
        // if(Config.environment == Config.EnvironmentType.Jk){
        //     port = 7525
        // }
        // else if(Config.environment == Config.EnvironmentType.xj){
        //     port = 7521
        // }
        // else if(Config.environment == Config.EnvironmentType.chaoyou){
        //     port = 7523
        // }
        // else if(Config.environment == Config.EnvironmentType.Online){
        //     port = 7520
        // }
        // else{
            port = 7236
        // }
        let cmd: string = "netstat -an |grep 'ESTABLISHED' |grep -i '" + port + "' |wc -l"
        Logger.log("getOnline==cmd=", cmd)
        return new Promise((resolve, reject) => {
            child_process.exec(cmd, (error, stdout, stderr) => {
                if (error) {
                    console.log("执行命令出错=getOnline=", error, stderr);
                    return
                }
                let online:number = parseInt(stdout)
                Logger.log("getOnline===", stdout, online)
                resolve(online)
            });
        })
    }
}